package com.mj.flink.examples.example.streamWordCount;

import com.mj.flink.examples.example.MyFlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStream;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * 流处理
 */
public class StreamWordCount {

    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment streamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment();
        String resource = "D:\\mj\\workspace\\flink-examples\\flink-first-example\\src\\main\\resources\\WorkdCount.txt";
        DataStream<String> dataStream = streamExecutionEnvironment.readTextFile(resource);

        SingleOutputStreamOperator<Tuple2<String,Integer>> resultStream = dataStream.flatMap(new MyFlatMapFunction()).keyBy(0).sum(1);
        resultStream.print();
        streamExecutionEnvironment.execute();
    }
}
